# This code reproduces Figure 2 from 
# Is the Supreme Court Veering Rightward? The Ebb-and-Flow of Representation
# by Stephen A. Jessee, Neil Malhotra, Maya Sen
# published in PNAS nexus

# for more information about ideology estimates see paper or contact 
# Stephen Jessee at sjessee@utexas.edu


# loading data objects
load("fig2-R-objects.RData")

# uncomment pdf command and dev.off command below
# to produce pdf of figure
#pdf("fig2.pdf",
#    height=6, width=6)
#
plot(D.av.idealg.by.year ~ c((2:7)+.05), 
     ylim=c(-1.6,1.6), xlim=c(1.9, 7.1),
     xaxt="n", col="blue", pch=19,
     bty="n", xlab="Survey Wave", ylab="Ideology")
segments(2+.05, RTABLE.2020[2,3], 2+.05, RTABLE.2020[2,4],
         lwd=2, col="blue")
segments(3+.05, RTABLE.2021[2,3], 3+.05, RTABLE.2021[2,4],
         lwd=2, col="blue")
segments(4+.05, RTABLE.2022[2,3], 4+.05, RTABLE.2022[2,4],
         lwd=2, col="blue")
segments(5+.05, RTABLE.2023[2,3], 5+.05, RTABLE.2023[2,4],
         lwd=2, col="blue")
segments(6+.05, RTABLE.2024[2,3], 6+.05, RTABLE.2024[2,4],
         lwd=2, col="blue")
segments(7+.05, RTABLE.2025[2,3], 7+.05, RTABLE.2025[2,4],
         lwd=2, col="blue")
axis(side=1, at=2:7, labels=c(#"2010", 
  "2020", "2021", "2022", "2023", "2024", "2025"))
abline(h=0, col="gray", lwd=2, lty=3)
points(2:7, rep(0,6), pch=19, col="gray")
points(R.av.idealg.by.year ~ c((2:7)+.1), col="red", pch=19)
segments(2+.1, RTABLE.2020[3,3], 2+.1, RTABLE.2020[3,4],
         lwd=2, col="red")
segments(3+.1, RTABLE.2021[3,3], 3+.1, RTABLE.2021[3,4],
         lwd=2, col="red")
segments(4+.1, RTABLE.2022[3,3], 4+.1, RTABLE.2022[3,4],
         lwd=2, col="red")
segments(5+.1, RTABLE.2023[3,3], 5+.1, RTABLE.2023[3,4],
         lwd=2, col="red")
segments(6+.1, RTABLE.2024[3,3], 6+.1, RTABLE.2024[3,4],
         lwd=2, col="red")
segments(7+.1, RTABLE.2025[3,3], 7+.1, RTABLE.2025[3,4],
         lwd=2, col="red")
points(c(SURVEY.2020$idealg_courtmajority[1], 
         SURVEY.2021$idealg_courtmajority[1],
         SURVEY.2022$idealg_courtmajority[1],
         SURVEY.2023$idealg_courtmajority[1],
         SURVEY.2024$idealg_courtmajority[1],
         SURVEY.2025$idealg_courtmajority[1]) ~
         I(c(2:7)-.1), pch=19)
segments(2-.1, JTABLE.2020[10,3], 2-.1, JTABLE.2020[10,4],
         lwd=2, col="black")
segments(3-.1, JTABLE.2021[10,3], 3-.1, JTABLE.2021[10,4],
         lwd=2, col="black")
segments(4-.1, JTABLE.2022[10,3], 4-.1, JTABLE.2022[10,4],
         lwd=2, col="black")
segments(5-.1, JTABLE.2023[10,3], 5-.1, JTABLE.2023[10,4],
         lwd=2, col="black")
segments(6-.1, JTABLE.2024[10,3], 6-.1, JTABLE.2024[10,4],
         lwd=2, col="black")
segments(7-.1, JTABLE.2025[10,3], 7-.1, JTABLE.2025[10,4],
         lwd=2, col="black")
legend('bottomleft', 
       c("Court", "Av. Resp Ideol", "Av. D Resp. Ideol", "Av. R Resp. Ideol"),
       pch=19, #lty=c(1,1,2,3), 
       col=c("black", "gray", "blue", "red"))
#dev.off()
